package com.mandao.concurrency.example.singleton;

import com.mandao.concurrency.annotations.ThreadSafe;

/**
 *  饿汉式
 *      单例实例在 类加载时创建
 *
 *    注意静态代码块的书写顺序
 */
@ThreadSafe
public class SingletonExample6 {

    private SingletonExample6(){}

    private static SingletonExample6 instance = null;

    static {
        instance = new SingletonExample6();
    }

    public static SingletonExample6 getInstance(){
        return instance;
    }

    public static void main (String[] args){
        System.out.println(getInstance().hashCode());
        System.out.println(getInstance().hashCode());
    }
}
